package br.com.wss;

import java.util.Map;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import br.com.wss.recursos.FindCampus;

public class TelaCampus extends Activity {
	private String[] cidades;
	private Map<String, String> linksCidades;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.model_list);
		FindCampus listCampus = new FindCampus();
		linksCidades = listCampus.find(); //Listando campus e url's.
		cidades = new String[linksCidades.keySet().size()];
		int cont = 0;
		for (String city : linksCidades.keySet()) {
			cidades[cont++] = city;
		}
		// titulo da tela
		TextView textView = (TextView) findViewById(R.id.textViewTitle);
		textView.setText("Cidades dos campus da UTFPR");

		ListView listView = (ListView) findViewById(R.id.listView_model);
		listView.setAdapter(new ArrayAdapter<String>(this, R.layout.row_cursos,
				cidades));

		listView.setOnItemClickListener(new OnItemClickListener() {

			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				String city = (String) ((TextView) view).getText();
				Intent i = new Intent("br.com.CURSOS");
				Bundle bundle = new Bundle();
				bundle.putString("campus", linksCidades.get(city));
				bundle.putString("city", cidades[position]);
				i.putExtras(bundle);
				startActivityForResult(i, 1);
			}

		});

	}

	public void onClickHome(View view) {
		Intent intent = new Intent(this, AppDroid.class);
		startActivity(intent);
	}

}
